package com.tulingxueyuan.mall.modules.pms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tulingxueyuan.mall.common.api.CommonPage;
import com.tulingxueyuan.mall.common.api.CommonResult;
import com.tulingxueyuan.mall.dto.BrandDTO;
import com.tulingxueyuan.mall.modules.pms.model.PmsBrand;
import com.tulingxueyuan.mall.modules.pms.service.PmsBrandService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * <p>
 * 品牌表 前端控制器
 * </p>
 *
 * @author Miao
 * @since 2022-05-19
 */
@RestController
@RequestMapping("/brand")
public class PmsBrandController {

    @Resource
    PmsBrandService pmsBrandService;

    /**
     * 商品品牌信息
     * Request URL: http://localhost:8099/brand/list?pageNum=1&pageSize=100
     * Request Method: GET
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public CommonResult<CommonPage<PmsBrand>> list(@RequestParam Long pageNum,
                                                   @RequestParam Long pageSize,
                                                   @RequestParam(value = "keyword",defaultValue = "") String keyword){
        Page page=pmsBrandService.list(pageNum,pageSize,keyword);
        return CommonResult.success(CommonPage.restPage(page));
    }

    /**
     * 品牌商
     * Request URL: http://localhost:8099/brand/update/factoryStatus
     * Request Method: POST
     * @return
     */
    @RequestMapping(value = "/update/factoryStatus",method = RequestMethod.POST)
    public CommonResult<Boolean> updateFactoryStatus(BrandDTO brandDTO){

        boolean result=pmsBrandService.updateStatus(brandDTO);

        if(result) {
            return CommonResult.success(result);
        }
        else {
            return CommonResult.failed();
        }
    }

    /**
     * 是否显示
     * Request URL: http://localhost:8099/brand/update/showStatus
     * Request Method: POST
     */
    @RequestMapping(value = "/update/showStatus",method = RequestMethod.POST)
    public CommonResult<Boolean> updateShowStatus(BrandDTO brandDTO){

        boolean result=pmsBrandService.updateShowStatus(brandDTO);

        if(result) {
            return CommonResult.success(result);
        }
        else {
            return CommonResult.failed();
        }
    }


}

